home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6918 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.rain.org!usenet
  2. From: "Guus Leeuw jr." <guusl@eiffel.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will it be auto-deleted?
  5. Date: Tue, 20 Feb 1996 08:59:50 -0800
  6. Organization: Interactive Software Engineering Inc. http://www.eiffel.com/
  7. Message-ID: <3129FE06.13F91E5F@eiffel.com>
  8. References: <1996Feb20.110314.46035@yogi.urz.unibas.ch>
  9. NNTP-Posting-Host: @outback.eiffel.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
  14.  
  15. Song Jin wrote:
  16. > I have a question:
  17. > void myfunction(void)
  18. > {
  19. >  double *mypointer = new double[100];
  20. >  .....
  21. > }
  22. > The mypointer and the buffer it pointed will be auto-deleted after returned
  23. > from myfunction, am I right?
  24.  
  25. No. The draft doesn't guarantee this. In fact you should `delete' everything
  26. that you `new'ed.
  27.  
  28. Be careful, though, with the arrays! When you apply `delete mypointer' in the
  29. above, it'll be fine. But as soon as `mypointer' starts pointing to other than
  30. an array of built-in objects, you will have to call `delete [] mypointer'. Just
  31. to make sure that all dtors are called ;-)
  32.  
  33. Regards,
  34.     Guus
  35.